package com.mingmen.supplier.activity;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.model.CommodityShopModel;
import com.mingmen.supplier.model.RestaurantModel;

import java.util.ArrayList;
import java.util.List;


public class RestaurantHistoryAdapter extends RecyclerView.Adapter<RestaurantHistoryAdapter.ViewHolder> {
    List<RestaurantModel.DataBean> mListData = new ArrayList<>();
    Context mContext;
    private OnItemClickListener mOnItemClickListener;
    private int checkedPosition = -1;
    String flag;

    //recycleview标签
    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<RestaurantModel.DataBean> myLiveList);
    }


    public RestaurantHistoryAdapter(Context context, List<RestaurantModel.DataBean> myLiveList, String flag) {
        this.mContext = context;
        this.mListData = myLiveList;
        this.flag = flag;
    }

    public void setDataList(List<RestaurantModel.DataBean> list) {
        mListData = list;

        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_restauranthis, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {

        RestaurantModel.DataBean dataBean = mListData.get(position);
        holder.startDate.setText(dataBean.getStartDate());
        holder.endDate.setText(dataBean.getEndDate());
//        holder.text_zhognzhi
        if (dataBean.getEndDate().equals("")) {

        }
        if (flag.equals("0")){
            holder.text_zhognzhi.setVisibility(View.GONE);
            holder.endDate.setVisibility(View.GONE);
        }else {
            holder.text_zhognzhi.setVisibility(View.VISIBLE);
            holder.endDate.setVisibility(View.VISIBLE);
        }

//        mOnItemClickListener.onItemClickListener(v, position, mListData);

    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView startDate;
        TextView endDate;
        TextView text_zhognzhi;

        public ViewHolder(View itemView) {
            super(itemView);
            startDate = itemView.findViewById(R.id.startDate);
            endDate = itemView.findViewById(R.id.endDate);
            text_zhognzhi = itemView.findViewById(R.id.text_zhognzhi);
        }
    }


}
